<?php
/**
 * Development tools for the Nephtali Web Framework documentation generation library.
 *
 * @author Adam Richardson of Envision Internet Consulting, LLC
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */

/**
 * General namespace for nlib doc_generator tools.
 */
namespace nlib\doc_generator;
/**
 *
 *
 * @return array Array of modes and their corresponding bitmasked filter values.
 */
function get_modes()
{
	return 	$modes = array(
		array(
			'MODE_HTML',
			(
				FILTER_PHP
			)
		),
		array(
			'MODE_PHP',
			(
				FILTER_NAMESPACE_BLOCKED +
				FILTER_NAMESPACE_STANDARD +
				FILTER_CLASS +
				FILTER_FUNCTION +
				FILTER_CONSTANT +
				FILTER_STRING_SINGLE +
				FILTER_STRING_DOUBLE +
				FILTER_COMMENT_SINGLE +
				FILTER_COMMENT_MULTI
			)
		),
		array(
			'MODE_NAMESPACE_BLOCKED',
			(
				FILTER_CLASS +
				FILTER_FUNCTION +
				FILTER_CONSTANT +
				FILTER_STRING_SINGLE +
				FILTER_STRING_DOUBLE +
				FILTER_COMMENT_SINGLE +
				FILTER_COMMENT_MULTI
			)
		),
		array(
			'MODE_NAMESPACE_STANDARD',
			(
				FILTER_CLASS +
				FILTER_FUNCTION +
				FILTER_CONSTANT +
				FILTER_STRING_SINGLE +
				FILTER_STRING_DOUBLE +
				FILTER_COMMENT_SINGLE +
				FILTER_COMMENT_MULTI
			)
		),
		array(
			'MODE_CLASS',
			(
				FILTER_FUNCTION +
				FILTER_CONSTANT +
				FILTER_STRING_SINGLE +
				FILTER_STRING_DOUBLE +
				FILTER_COMMENT_SINGLE +
				FILTER_COMMENT_MULTI
			)
		),
		array(
			'MODE_FUNCTION',
			(
				FILTER_STRING_SINGLE +
				FILTER_STRING_DOUBLE +
				FILTER_COMMENT_SINGLE +
				FILTER_COMMENT_MULTI
			)
		),
		array(
			'MODE_CONSTANT',
			(
				FILTER_STRING_SINGLE +
				FILTER_STRING_DOUBLE
			)
		),
		array('MODE_STRING_SINGLE',0),
		array('MODE_STRING_DOUBLE',0),
		array('MODE_COMMENT_SINGLE',0),
		array('MODE_COMMENT_MULTI', 0)
	);
}
/**
 * Determines the current line number represented in the reverse-ordered character array.
 *
 * @staticvar string $total_lines
 * @param <type> $char_array
 * @return <type>
 */
function current_line_number($char_array)
{
	static $total_lines = null;
	$string = implode('', $char_array);

	if (is_null($total_lines)) $total_lines = \substr_count ($haystack = $string, $needle = "\n");

	return $total_lines - \substr_count($haystack = $string, $needle = "\n") + 1;
}
/**
 * Return the string lable for the current mode.
 *
 * @param int $mode One of the MODE_ constants, which are bitmasks of the filters for the mode.
 * @return string
 */
function mode_name($mode)
{
	switch ($mode) {
		case MODE_CLASS:
			return "Class";
		case MODE_COMMENT_MULTI:
			return "Comment (multi-line)";
		case MODE_COMMENT_SINGLE:
			return "Comment (single line)";
		case MODE_CONSTANT:
			return "Constant";
		case MODE_FUNCTION:
			return "Function";
		case MODE_HTML:
			return "HTML";
		case MODE_NAMESPACE_BLOCKED:
			return "Namespace (blocked)";
		case MODE_NAMESPACE_STANDARD:
			return "Namespace (standard)";
		case MODE_PHP:
			return "PHP";
		case MODE_STRING_DOUBLE:
			return "String (double)";
		case MODE_STRING_SINGLE:
			return "String (single)";
	}
}
/**
 * Generate the code for the mode constants, automatically performing the bitmask math.
 *
 * @param array $modes
 * @return string
 */
function generate_mode_bitmasks(array $modes)
{
	$output = '';

	foreach ($modes as $key => $mode) {
		// use value atleast as large as top filter value or you'll regret it
		$base2 = 16384 << $key;
		$output .= "const ".$mode[0]." = ".($base2 + $mode[1]).";\n\n";
	}

	return $output;
}

?>